package com.zxh.zhenxihuan.service.impl;

import com.zxh.zhenxihuan.entity.ShopCar;
import com.zxh.zhenxihuan.mapper.ShopCarMapper;
import com.zxh.zhenxihuan.service.ShopCarService;
import com.zxh.zhenxihuan.util.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author:geQiang
 * @version:1.0
 * @date:2019/8/10
 * @description:com.zxh.zhenxihuan.service.impl
 */
@Service("shopCarService")
public class ShopCarServiceImpl implements ShopCarService {
    @Resource
    private ShopCarMapper shopCarMapper;
    @Override
    @Transactional(propagation = Propagation.REQUIRED,timeout = -1,rollbackFor = Exception.class)
    public Page<ShopCar> page(Integer num, Integer count) {
        Integer pageNum=1;
        try{
            pageNum=Integer.valueOf(num) ;
        }catch(Exception e){
            e.printStackTrace();
        }
        Integer pageCount=10;
        try{
            pageCount=Integer.valueOf(count);
        }catch(Exception e){
            e.printStackTrace();
        }
        Page<ShopCar> page=new Page<>();
        page.init(pageNum,pageCount,getSum());
        page.setList(getAll(page.getRowNum(),pageCount));
        return page;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,timeout = -1,rollbackFor = Exception.class)
    public Integer getSum() {
        Integer num=shopCarMapper.getSum();
        System.out.println(num+">>>>>>>>>>>>>>>>>>>>>>>>>");
        return num;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,timeout = -1,rollbackFor = Exception.class)
    public List<ShopCar> getAll(Integer start, Integer end) {
        List<ShopCar> list = shopCarMapper.getAllShopCar(start, end);
        for (ShopCar shopCar : list) {
            System.out.println(shopCar);
        }
        return list;
    }


}
